package com.daohang361.imqq.hotLoader;

import java.lang.reflect.Proxy;

/** 
 * @author naner E-mail:likun3344@163.com 
 * @create time：2011-5-13 下午08:43:57 
 * java代理工厂实现  
 */  
public class DynamicProxyFactory {   
    /*  
     * 方法处理者  
     */  
    private DefaultInvocationHandler invocationHandler;   
  
    public DynamicProxyFactory() {   
        this(null);   
    }   
  
    /**  
     *   
     * @param invocationHandler  
     */  
    public DynamicProxyFactory(DefaultInvocationHandler invocationHandler) {   
        if (invocationHandler == null) {   
            this.invocationHandler = new DefaultInvocationHandler();   
        } else {   
            this.invocationHandler = invocationHandler;   
        }   
    }   
  
    /**  
     * 创建代理对象  
     * @param target  
     * @return  
     */  
    public Object newProxyInstance(final Object target) {   
        invocationHandler.setTarget(target);   
        Object proxy = Proxy.newProxyInstance(target.getClass()   
                .getClassLoader(), target.getClass().getInterfaces(),   
                invocationHandler);   
        return proxy;   
    }   
}  
